package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAddressMapper;
import com.qf.pojo.DtsAddress;
import com.qf.service.DtsAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * projectName:workspace_6
 * author:hyn
 * time:2021/12/1 11:27
 * description:
 */
@Service
public class DtsAddressServiceImpl implements DtsAddressService {
    @Autowired
    private DtsAddressMapper addressMapper;
    @Override
    public IPage<DtsAddress> findAll(String name, String userId, Integer limit, Integer page, String sort, String order) {
        IPage<DtsAddress> ipage = new Page(page,limit);
        QueryWrapper<DtsAddress> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(name)){
            wrapper.like("name",name);
        }
        if(!StringUtils.isEmpty(userId)){
            wrapper.like("user_id",userId);
        }
        if("asc".equals(order)){
            wrapper.orderByAsc(sort);
        }else{
            wrapper.orderByDesc(sort);
        }
        IPage<DtsAddress> p = addressMapper.selectPage(ipage, wrapper);
        return p;
    }
}
